<template>
  <div>
    <integrity-form ref="integrityForm" @search="handleSearch" @addUser="handleAddUser" />
    <integrity-table ref="integrityTable" @edit="handleEdit" />
    <integrity-modal ref="integrityModal" @refresh="handleRefresh" />
    <dept-position-man mode="free" ref="deptPositionMan" @handleSelected="handleManSelect" />
  </div>
</template>

<script>
import IntegrityForm from './IntegrityForm'
import IntegrityTable from './IntegrityTable'
import IntegrityModal from './IntegrityModal'
import DeptPositionMan from '@/components/DeptPositionMan'
import { saveUserIntegrity } from '@/api/archives'
import { openNotification } from '@/utils/util'
export default {
  components: {
    IntegrityForm,
    IntegrityTable,
    IntegrityModal,
    DeptPositionMan
  },
  methods: {
    handleRefresh() {
      this.$refs.integrityTable.handleGetList()
    },
    handleSearch(obj) {
      this.$refs.integrityTable.handleGetList(obj)
    },
    handleAddUser() {
      this.$refs.deptPositionMan.show()
    },
    async handleManSelect(value) {
      console.log('value', value)
      if (value.userId) {
        const res = await saveUserIntegrity({ userId: value.userId })
        if (res.state === '000000') {
          openNotification('success', '新增廉政用户信息成功')
          this.$refs.integrityTable.handleGetList()
        }
      } else {
        this.$message.error('请选择某个人员')
      }
    },
    handleEdit(bool, obj) {
      this.$refs.integrityModal.edit(bool, obj)
    }
  }
}
</script>
